#include"Vector_2D.h"

Vector_2D::Vector_2D()
{
    val.setPos(0, 0);
    x = 0; y = 0;
    len = 0;
}
Vector_2D::Vector_2D(int xcoor, int ycoor)
{
    x = xcoor, y = ycoor;
    val.setPos(x, y);
    len = sqrt(x * x + y * y);
}
Vector_2D::Vector_2D(const Position& start, const Position& end)
{
    val = end - start;
    x = val.x; y = val.y;
    len = sqrt(x * x + y * y);
}
Vector_2D::Vector_2D(const Position& obj)
{
    val = obj;
    x = val.x; y = val.y;
    len = sqrt(x * x + y * y);
}

Vector_2D operator+(const Vector_2D obj1, const Vector_2D obj2)
{
    Position temp = obj1.val + obj2.val;
    return Vector_2D(temp);
}
Vector_2D operator-(const Vector_2D obj1, const Vector_2D obj2)
{
    Position temp = obj1.val - obj2.val;
    return Vector_2D(temp);
}
Vector_2D Vector_2D::operator+=(const Vector_2D obj)//!!!
{
    this->val += obj.val;
    this->x = this->val.x; this->y = this->val.y;
    this->cal_len();
    return Vector_2D(this->val);
}
Vector_2D Vector_2D::operator-=(const Vector_2D obj)//!!!
{
    this->val -= obj.val;
    this->x = this->val.x; this->y = this->val.y;
    this->cal_len();
    return Vector_2D(this->val);
}
Vector_2D Vector_2D::operator*(const double& num) const
{
    Position temp(val.x * num, val.y * num);
    return Vector_2D(temp);
}
Vector_2D Vector_2D::operator/(const double& num) const
{
    Position temp(val.x / num, val.y / num);
    return Vector_2D(temp);
}
Vector_2D Vector_2D::operator=(const Vector_2D& obj)//!!!
{
    this->val = obj.val;
    this->x = this->val.x; this->y = this->val.y;
    this->cal_len();
    return Vector_2D(this->val);
}
std::ostream& operator<<(std::ostream& output, Vector_2D obj)
{
    output << "(" << obj.x << "," << obj.y << ")";
    return output;
}

void Vector_2D::set_zeroVec()
{
    this->val.x = 0; this->val.y = 0;
    this->x = 0; this->y = 0;
    cal_len();
}
void Vector_2D::setVec(double x, double y)
{
    this->val.x = x; this->val.y = y;
    this->x = x; this->y = y;
    cal_len();
}
void Vector_2D::cal_len()
{
    double x0 = this->val.x, y0 = this->val.y;
    this->len = sqrt(x0 * x0 + y0 * y0);
}

double Vector_2D::get_len()
{
    return this->len;
}